/*
 * FileSystem.h
 *
 *  Created on: Jul 10, 2009
 *      Author: yanir
 */

#ifndef FILESYSTEM_H_
#define FILESYSTEM_H_


#include <vector>

#include "LowLevel.h"



class FileSystem {


private:

        LowLevel* _LL;
        pthread_mutex_t _mutex_lock;

public:
        FileSystem();
        virtual ~FileSystem();

        /**
         * creates a file returning its i-node number. Flag indicates whether the file to create is a regular file or a soft link.
         * flags : file - f ,  directory - d  , soft-link - s
         */
        int createFile(char flag);

        /**
         *  creates a directory, returning its i-node number.
         */
        int createDir();

        /**
         * Returns the type of the file this i-node represents.
         */
        int getFileType(int i_node);

        /**
         * reads nBytes (at most) from the given file (represented by this i-node) at the given offset inside the file into the buffer.
         */
        int f_read(int i_node,char* buffer,int offset,int nBytes);

        /**
         * writes nBytes (at most) to the given file (represented by this i-node) at the given offset inside that file, from the buffer.
         *  If the amount to be written exceeds the current allocated block, a new block should be allocated to accommodate the rest of the data.
         *      Notice that both f_read and f_write only work on normal files (not directories).
         */
        int f_write(int i_node,char* buffer,int offset,int nBytes);


        /**
         * reads the entire content of the directory file specified by the given i-node.
         * This information is then entered into a data structure (a vector or list) that lists the files in this directory.
         * Each element in this list therefore contains a filename and i-node number.
         */
        vector<dir*>* d_read(int i_node);

        /*
         *  replaces the content of the given directory file (specified by i-node) with the information stored in the list.
         *   The list has the same format as that returned by d_read().
         */
        int d_write(int i_node,vector<dir*>* list);

        /**
         * delete the file.
         */
        int f_delete(int i_node);

        /**
         *  delete the directory if it is empty.
         */
        int d_delete(int i_node);

        /** returns an empty buffer of 12 bytes */
        char* get_empty_fn();

        /** creates a root i node**/
        int create_root();

        /** gets the root i node **/
        int get_root_i_node();

        int get_hardLinks_num(int i_node);

		 /**
		  * sets the number of hard links of an i node
		  */
		 void set_hardLinks_num(int i_node,int hl_num);

		 /** gets a file size **/

		 int get_file_size(int i_node);

		 int check_space();



};

#endif /* FILESYSTEM_H_ */
